package com.cskaoyan._19collection._05list.arraylist;

import java.util.ArrayList;

/**
 * @author Macro_Ray
 * @since 2024/3/30 11:52
 */
// 定义一个集合，添加学生对象，并进行遍历
// 学生类的属性：姓名、年龄
public class ArrayListTest3 {
    public static void main(String[] args) {
        // 创建集合对象
        ArrayList<Student> students = new ArrayList<>();
        // 添加学生对象
        students.add(new Student("张三", 20));
        students.add(new Student("李四", 18));
        students.add(new Student("皇说", 26));
        students.add(new Student("张无忌", 22));
        students.add(new Student("赵敏", 23));
        // 遍历
        for(Student stu:students){
            System.out.println("姓名：" + stu.getName() + "，年龄：" + stu.getAge());
        }
    }
}

class Student {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}